In [1]:
from IPython.display import Image
Image(url='https://vesg.ipsl.upmc.fr/thredds/fileServer/IPSLFS/jservon/CliMAF_Notebooks_html/CliMAF-logo-small.png') 
Out[1]:

CliMAF: Climate Model Assessment Framework

A science-oriented framework to ease the analysis of climate model simulations

WP5 ANR Convergence
Project leaders: Stéphane Sénési (CNRM-GAME), Jérôme Servonnat (LSCE-IPSL)
Developers: Ludivine Vignon (CNRM-GAME), Laurent Franchisteguy (CNRM-GAME), Patrick Brockmann (LSCE-IPSL), Sylvana Ramos-Buarque (CNRM-GAME)
Beta-testing: Olivier Marti (LSCE-IPSL), Marie-Pierre Moine (CERFACS), Emilia Sanchez-Gomez (CERFACS)
Contributors: you!

The goals of CliMAF are to provide the scientists with simplified and science-oriented means for :

  • accessing both model and references data
  • pre-tretament (period and geographical selections, regridding, averaging like seasonal mean computations...)
  • plotting maps, cross-sections and time series
  • building atlases
  • plugging personal scripts in an atlas or in an analysis workflow
  • sharing such scripts
  • handlling ensembles (multi-model, multi-realization) CliMAF provides full managment of the outputs by handling the naming of the output files; it also stores the information on "how I obtained this file" under the form of an expression called CRS (CliMAF Reference Syntax) that allows checking for the existing files and avoid recomputing the same files twice (or more).

Getting started with plot()

    1. basic 2D map
    1. edit the titles
    1. change font sizes
    1. change color palette, isolines
    1. ocean view: choose the longitude in the middle of the plot
    1. use any ncl resource with 'options'
      • 6.1. Raster plot (with 'options')
    1. Polar Stereographic projections
    1. add the contours of an auxilliary file
    1. Vectors of a wind field
    1. add a pattern (like statistical significance)
    1. Plot a region on an ORCA grid: need to regrid first on a regular grid
    1. Zonal mean atmospheric plot
    1. Various fancy projections available with 'proj'
      • 13.1 the cool Satellite projection

Import climaf

In [1]:
from climaf.api import *
clog('critical') # min verbosity = critical < warning < info < debug = max verbosity
CliMAF version = 1.2.13
CliMAF install => /ciclad-home/jservon/Evaluation/CliMAF/climaf_installs/climaf_1.2.13_beta
python => /prodigfs/ipslfs/dods/jservon/miniconda/envs/analyse_env_2.7/bin/python
---
Required softwares to run CliMAF => you are using the following versions/installations:
ncl 6.6.2 => /prodigfs/ipslfs/dods/jservon/miniconda/envs/analyse_env_2.7/bin/ncl
cdo 1.9.6 => /opt/nco/1.9/bin/cdo
nco (ncks) 4.5.2 => /opt/nco-4.5.2/bin/ncks
ncdump fichier => /prodigfs/ipslfs/dods/jservon/miniconda/envs/analyse_env_2.7/bin/ncdump
Check stamping requirements
nco (ncatted) found -> /opt/nco-4.5.2/bin/ncatted
convert found -> /usr/bin/convert
pdftk found -> /usr/bin/pdftk
exiv2 found -> /ciclad-home/jservon/Evaluation/CliMAF/climaf_installs/climaf_1.2.13_beta/bin/exiv2
---
Cache directory set to : /data/jservon/climafcache (use $CLIMAF_CACHE if set) 
Cache directory for remote data set to : /data/jservon/climafcache/remote_data (use $CLIMAF_REMOTE_CACHE if set) 
warning  : When defining temp_penalty : duplicate declaration for input #0
warning  : When defining cquantile : duplicate declaration for input #0
warning  : When defining cquantile : duplicate declaration for input #0
Available macros read from ~/.climaf.macros are : []

0. Get a dataset

In [2]:
dat = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='v20130101',
         period='1980-2005', variable='tos', realm='ocean' )
summary(dat)
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tos/tos_Omon_CNRM-CM5_historical_r1i1p1_198001-198912.nc
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tos/tos_Omon_CNRM-CM5_historical_r1i1p1_199001-199912.nc
/bdd/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tos/tos_Omon_CNRM-CM5_historical_r1i1p1_200001-200512.nc
Out[2]:
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2005,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': 'ocean',
 'root': '/bdd',
 'simulation': '',
 'table': '*',
 'variable': 'tos',
 'version': 'v20130101'}

1. Basic plot

In [3]:
myplot = plot(time_average(dat))
iplot(myplot)
Out[3]:

2. Edit the titles

In [4]:
myplot = plot(time_average(dat),
              title='My CliMAF plot',
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model)
iplot(myplot)
Out[4]:

3. Change the font size

In [5]:
myplot = plot(time_average(dat),
              # -- Title
              title='My CliMAF plot',
                  tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
                  gsnStringFontHeightF=0.02, #default=0.012
              )
iplot(myplot)
Out[5]:

Size of the Axis labels, colorbar labels, the fonts: see http://climaf.readthedocs.org/en/dev/scripts/plot.html?highlight=plot

4. Change the colorpalette and the isolines

In [6]:
myplot = plot(time_average(dat),
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
                  # -- Colorpalette
                  color='WhViBlGrYeOrRe',
                  # -- Add contours
                  contours=1,
                  # -- Isolines
                  min=-1,max=30,delta=1,
                  # -- And add an offset to switch from K to degC
                  offset = -273.15
              )
iplot(myplot)
Out[6]:

5. Ocean view: put longitude 200°E in the center (mpCenterLonF=200), and shade the land with grey (focus='ocean')

In [7]:
myplot = plot(regridn(time_average(dat),cdogrid='r360x180'),
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
                  # -- Longitude in the middle of the plot
                  mpCenterLonF=200,
                  # -- Grey on lands
                  focus='ocean'
              )
iplot(myplot)
Out[7]:

6. options = how to use any ncl resource : options

In [25]:
myplot = plot(regridn(time_average(dat),cdogrid='r360x180'),
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
                  # -- OPTIONS
                  options='pmLabelBarWidthF=0.065'
                  #options='pmLabelBarWidthF=0.065|'+\
                  #        'pmLabelBarOrthogonalPosF=0.01|'+\
                  #        'lbLabelFontHeightF=0.01|'+\
                  #        'tmXBLabelFontHeightF=0.01|'+\
                  #        'tmYLLabelFontHeightF=0.01'
              )
iplot(myplot)
Out[25]:

6.1 Create a raster plot with options

In [10]:
myplot = plot(regridn(time_average(dat),cdogrid='r90x45'), # --> Interpolate to coarser grid to see the raster
              # -- Title
              title='Raster plot with CliMAF',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
                  # -- deactivate the contours
                  # contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
                  # -- Use OPTIONS for the argument of the Raster plot
                  options='cnFillMode=RasterFill|cnRasterSmoothingOn=False'
              )
iplot(myplot)
Out[10]:

7. Polar stereographic views

In [26]:
# --> Set proj to 'NH' or 'SH'; the two additionnal characters set the last latitude visible 

projNH = 'NH20'
myplotNH = plot(regridn(clim_average(dat,'ANM'),cdogrid='r360x180'),
              # -- Title
              title=projNH+' plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
                  # -- Northern Hemisphere projection
                  proj=projNH
              )

projSH = 'SH60'
myplotSH = plot(regridn(clim_average(dat,'ANM'),cdogrid='r360x180'),
              # -- Title
              title=projSH+' plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # or: colors='-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30'
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
                  # -- Northern Hemisphere projection
                  proj=projSH,
              )

iplot(cpage(fig_lines=[[myplotNH,myplotSH]]))
Out[26]:

8. Add the contours of an auxillary file

In [10]:
# -- Get an auxillary file
aux = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='v20130101',
         period='1980-2005', variable='sic')#, realm='ocean' )
summary(aux)
/prodigfs/project/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/seaIce/OImon/r1i1p1/v20130101/sic/sic_OImon_CNRM-CM5_historical_r1i1p1_185001-200512.nc
Out[10]:
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2005,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': '*',
 'root': '/prodigfs/project',
 'simulation': '',
 'table': '*',
 'variable': 'sic',
 'version': 'v20130101'}
In [11]:
# --> Provide the auxillary field as a second argument
myplotNH = plot(time_average(dat),
                    # -- Auxillary field provided as a second argument
                    time_average(aux),
                    # -- Add contours
                    contours='1 5 10 15',
                    # -- Handle options on the auxillary field
                    aux_options='cnLineThicknessF=8|cnLineColor=Red',
              # -- Title
              title='SST + Sea Ice contours',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean',
              # -- Northern Hemisphere projection
              proj='NH50'
              )
iplot(myplotNH)
Out[11]:

9. Add the vectors of a wind field

In [21]:
tauu = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='v20130101',
          period='1980-2005', variable='tauuo')
tauv = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='v20130101',
          period='1980-2005', variable='tauvo')
summary(tauv)
/prodigfs/project/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tauvo/tauvo_Omon_CNRM-CM5_historical_r1i1p1_198001-198912.nc
/prodigfs/project/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tauvo/tauvo_Omon_CNRM-CM5_historical_r1i1p1_199001-199912.nc
/prodigfs/project/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/ocean/Omon/r1i1p1/v20130101/tauvo/tauvo_Omon_CNRM-CM5_historical_r1i1p1_200001-200512.nc
Out[21]:
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2005,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': '*',
 'root': '/prodigfs/project',
 'simulation': '',
 'table': '*',
 'variable': 'tauvo',
 'version': 'v20130101'}
In [22]:
myplot = plot(regridn(time_average(dat),cdogrid='r360x180'),
                  # -- Specific to the plot of wind vectors:
                  None,
                  time_average(tauu),time_average(tauv),
                  vcRefLengthF=0.005, vcRefMagnitudeF=0.03,vcMinDistanceF=0.01,vcLineArrowColor='White',
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean'
              )
iplot(myplot)
Out[22]:

10. Add a pattern

In [24]:
myplot = plot(regridn(time_average(dat),cdogrid='r360x180'),
                  # -- Pattern
                  regridn(time_average(dat),cdogrid='r360x180'),
                  shade_above = 298,
                  #shade_below = 5,
                  #offset_aux = -273.15,
                  #shading_options='gsnShadeHigh=6',
                  # https://www.ncl.ucar.edu/Document/Graphics/Images/fillpatterns.png
              # -- Title
              title='My CliMAF plot',
              tiMainFontHeightF=0.03,#default = 0.025
              # -- Subtitles
              gsnLeftString=dat.variable,
              gsnCenterString=dat.period,
              gsnRightString=dat.model,
              gsnStringFontHeightF=0.02, #default=0.012
              # -- Colorpalette
              color='WhViBlGrYeOrRe',
              # -- Add contours
              #contours=1,
              # -- Isolines
              min=-1,max=30,delta=1,
              # -- And add an offset to switch from K to degC
              offset = -273.15,
              # -- Longitude in the middle of the plot
              mpCenterLonF=200,
              # -- Grey on lands
              focus='ocean'
              )
iplot(myplot)
Out[24]:

11. Plot a region on an ORCA grid: need to regrid first on a regular grid!

In [25]:
rgrd_dat = regridn(time_average(dat),cdogrid='r360x180')
myplot = plot(llbox(rgrd_dat,lonmin=-90,lonmax=20,latmin=0,latmax=90), title='North Atlantic')

iplot(myplot)
Out[25]:

12. Zonal mean atmospheric field

In [26]:
# -- A zonal field
## Add the contours of an auxillary file
ua_dat = ds(project='CMIP5', model='CNRM-CM5', experiment='historical', frequency='monthly', version='latest',
            period='1980-2005', variable='ua')#, realm='ocean' )
summary(ua_dat)
/prodigfs/project/CMIP5/output/CNRM-CERFACS/CNRM-CM5/historical/mon/atmos/Amon/r1i1p1/latest/ua/ua_Amon_CNRM-CM5_historical_r1i1p1_195001-200512.nc
Out[26]:
{'domain': 'global',
 'experiment': 'historical',
 'frequency': 'monthly',
 'model': 'CNRM-CM5',
 'period': 1980-2005,
 'project': 'CMIP5',
 'realization': 'r1i1p1',
 'realm': '*',
 'root': '/prodigfs/project',
 'simulation': '',
 'table': '*',
 'variable': 'ua',
 'version': 'latest'}
In [27]:
zonmean_plot = plot(zonmean(clim_average(ua_dat,'ANM')),title='Zonal Wind Speed',contours=1,y='lin')
iplot(zonmean_plot)
Out[27]:

13. Various fancy projections available with proj

see all projections here: https://www.ncl.ucar.edu/Document/Graphics/map_projections.shtml

In [13]:
pp = dict(gsnLeftString=dat.variable,
          gsnCenterString=dat.period,
          gsnRightString=dat.model)

proj = 'CylindricalEqualArea'
p1 = plot(time_average(dat), title=proj, proj=proj, **pp)
proj = 'Robinson'
p2 = plot(time_average(dat), title=proj, proj=proj, **pp)
proj = 'Mollweide'
p3 = plot(time_average(dat), title=proj, proj=proj, **pp)
proj = 'Orthographic'
p4 = plot(time_average(dat), title=proj, proj=proj, **pp)

iplot(cpage(fig_lines = [[p1,p2],[p3,p4]]))
Out[13]:

13.1 : Satellite projection

In [26]:
pp = dict(gsnLeftString=dat.variable,
          gsnCenterString=dat.period,
          gsnRightString=dat.model,
)

p1 = plot(time_average(dat), proj='Satellite',
              title='mpSatelliteDistF=3.0',
              options='mpCenterLonF=-40.|mpCenterLatF=45.|mpSatelliteDistF=3.0',
          **pp
          )
p2 = plot(time_average(dat), proj='Satellite',
              title='mpSatelliteDistF=2.0',
              options='mpCenterLonF=-40.|mpCenterLatF=45.|mpSatelliteDistF=2.0',
          **pp
          )
p3 = plot(time_average(dat), proj='Satellite',
              title='mpSatelliteDistF=5.0',
              options='mpCenterLonF=-40.|mpCenterLatF=45.|mpSatelliteDistF=5.0',
          **pp
          )
p4 = plot(time_average(dat), proj='Satellite',
              title='mpCenterLonF=130.|mpCenterLatF=-25.',
              options='mpCenterLonF=130.|mpCenterLatF=-25.|mpSatelliteDistF=3.0',
          **pp
          )
p5 = plot(time_average(dat), proj='Satellite',
              title='mpCenterLonF=295.|mpCenterLatF=-10.',
              options='mpCenterLonF=295.|mpCenterLatF=-10.|mpSatelliteDistF=3.0',
          **pp
          )


iplot(cpage(fig_lines=[[p1,p2,p3],[p4,p5,None]]))
Out[26]:
In [ ]: